Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PhpVersion param on isSmallerThanOrEqual and isGreaterThanOrEqual #3478

Merged
merged 7 commits into from
Sep 25, 2024

Conversation

VincentLanglet
Copy link
Contributor

As recommended in phpstan/phpstan#11732 (comment)

I'll do the implementation/fix in another PR, to be sure to not delay the signature update.

@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 2.0.x. PHPStan 2.0 is not going to be released for months. If your code is relevant on 1.12.x and you want it to be released sooner, please rebase your pull request and change its target to 1.12.x.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also other potential methods to add it to:

  • getSmallerType
  • getSmallerOrEqualType
  • getGreaterType
  • getGreaterOrEqualType

@@ -16,6 +17,6 @@ public function isAcceptedWithReasonBy(Type $acceptingType, bool $strictTypes):

public function isGreaterThan(Type $otherType): TrinaryLogic;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, var_dump('' < 0); is true on PHP 8 but false on PHP 7.4

@@ -217,7 +217,7 @@ public function toArrayKey(): Type;

public function isSmallerThan(Type $otherType): TrinaryLogic;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about here?

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention it in UPGRADING.md in minor breaks section at the bottom. Thanks!

@staabm
Copy link
Contributor

staabm commented Sep 25, 2024

I think we need a similar PR for methods which currently use PhpVersionStaticAccessor::getInstance() instead of using a PhpVersion parameter explicitly?

@ondrejmirtes
Copy link
Member

That would be awesome!

@VincentLanglet
Copy link
Contributor Author

I think we need a similar PR for methods which currently use PhpVersionStaticAccessor::getInstance() instead of using a PhpVersion parameter explicitly?

It's used by

  • StubValidator => seems easy to change
  • ConstantArrayType::findTypeAndMethodNames => Need to pass phpVersion to isCallable and getCallableParametersAcceptors
  • ConstantStringType::isCallable

Changing the signature of isCallable seems to have a bigger impact since it's used in

  • Type::inferTemplateTypes
  • Type::isSubTypeOf
  • Type::isSuperTypeOf
  • Type::acceptsWithReason
  • Type::traverseSimultaneously

And changing those signature lead to too many changes...

@ondrejmirtes
Copy link
Member

Yeah, I wouldn't want to do this for Type::isCallable() / ConstantArrayType::findTypeAndMethodNames. It's just covering a quirk/edge-case of pre-PHP 8.0 behaviour.

@ondrejmirtes ondrejmirtes merged commit ac91552 into phpstan:2.0.x Sep 25, 2024
69 of 82 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

@VincentLanglet VincentLanglet deleted the phpVersion branch September 25, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants